package com.app.piemoment.entity;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

public class MatchInfo implements Parcelable{
	private int mid;
	private int is_match_expired;//0=false 1 = true;
	private String calculated_at;
	private String match_status;
	private String target_decision;
	private String my_decision;
	private OppositeInfo target_info;
	
	public MatchInfo() {
		super();
	}

	MatchInfo(Parcel in) {
		this.mid = in.readInt();
		this.is_match_expired = in.readInt();
		this.calculated_at = in.readString();
		this.match_status = in.readString();
		this.target_decision = in.readString();
		this.my_decision = in.readString();
		this.target_info = in.readParcelable(OppositeInfo.class.getClassLoader());
	}

	public static final Parcelable.Creator<MatchInfo> CREATOR = new Creator<MatchInfo>() {
		@Override
		public MatchInfo[] newArray(int size) {
			return new MatchInfo[size];
		}

		@Override
		public MatchInfo createFromParcel(Parcel source) {
			return new MatchInfo(source);
		}
	};

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(mid);
		dest.writeInt(is_match_expired);
		dest.writeString(calculated_at);
		dest.writeString(match_status);
		dest.writeString(target_decision);
		dest.writeString(my_decision);
		dest.writeParcelable(target_info, flags);

	}

	
	public int getMid() {
		return mid;
	}
	public void setMid(int mid) {
		this.mid = mid;
	}
	public int isIs_match_expired() {
		return is_match_expired;
	}
	public void setIs_match_expired(int is_match_expired) {
		this.is_match_expired = is_match_expired;
	}
	public String getCalculated_at() {
		return calculated_at;
	}
	public void setCalculated_at(String calculated_at) {
		this.calculated_at = calculated_at;
	}
	public String getMatch_status() {
		return match_status;
	}
	public void setMatch_status(String match_status) {
		this.match_status = match_status;
	}
	public String getTarget_decision() {
		return target_decision;
	}
	public void setTarget_decision(String target_decision) {
		this.target_decision = target_decision;
	}
	public String getMy_decision() {
		return my_decision;
	}
	public void setMy_decision(String my_decision) {
		this.my_decision = my_decision;
	}
	public OppositeInfo getTarget_info() {
		return target_info;
	}
	public void setTarget_info(OppositeInfo target_info) {
		this.target_info = target_info;
	}
	public void parser(JSONObject jsonEntity) throws JSONException {
		if(jsonEntity!=null) {
			if(jsonEntity.has("match_id")) {
				setMid(jsonEntity.getInt("match_id"));
			}
			if(jsonEntity.has("is_match_expired")) {
				setIs_match_expired(jsonEntity.getBoolean("is_match_expired")?1:0);
			}
			if(jsonEntity.has("calculated_at")) {
				setCalculated_at(jsonEntity.getString("calculated_at"));
			}
			if(jsonEntity.has("match_status")) {
				setMatch_status(jsonEntity.getString("match_status"));
			}
			if(jsonEntity.has("target_decision")) {
				setTarget_decision(jsonEntity.getString("target_decision"));
			}
			if(jsonEntity.has("my_decision")) {
				setMy_decision(jsonEntity.getString("my_decision"));
			}
			if(jsonEntity.has("target_info")) {
				OppositeInfo info = new OppositeInfo();
				info.parser(jsonEntity.getJSONObject("target_info"));
				setTarget_info(info);
			}
		}
		
	}
}
